<template>
  <div class="common-layout home">
    <el-container>
      <el-header>
        <el-row :gutter="20">
          <el-col :span="4"><img src="../assets/logo.png" class="header-logo" /></el-col>
          <el-col :span="16">
            <h2>后台管理系统</h2>
          </el-col>
          <el-button @click="delToken">退出登录</el-button>
        </el-row>
      </el-header>
      <el-container>
        <el-aside width="250px">
          <el-menu active-text-color="#3c8dbc" background-color="#2f4050" class="el-menu-vertical-demo" default-active="2" text-color="#fff" router>
            <!-- router 开启路由模式，通过el-menu-item index来进行跳转 -->
            <el-menu-item :index="item.path" v-for="item in list" :key="item.path">
              <!-- <el-icon><icon-menu /></el-icon> -->
              <span>{{ item.meta.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

const router = useRouter()
const list = router.getRoutes().filter((v) => v.meta.isShow)

const delToken = () => {
  localStorage.removeItem('token')
  router.push('/login')
}
</script>

<style lang="scss" scoped>
.el-header {
  color: #fff;
  background: #3c8dbc;
  height: 80px;
  padding-left: 0;

  .el-row {
    .el-col {
      text-align: center;
      height: 80px;
      line-height: 80px;

      ::v-deep &:first-child {
        // background-color: #367fa9;
        padding-right: 0px !important;
      }
    }

    .header-logo {
      height: 80px;
    }
  }
}

.el-aside {
  text-align: center;

  .el-menu {
    height: calc(100vh - 80px);
  }
}
.el-button {
  margin: auto;
}
</style>
